package com.frxuexi.park2303.notice

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.frxuexi.base.entity.NoticeBeanItem
import com.frxuexi.base.mvi.BaseActivity
import com.frxuexi.base.mvi.UiState
import com.frxuexi.park2303.R
import com.frxuexi.park2303.databinding.ActivityNoticeDetailBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@Route(path = "/app/NoticeDetailActivity")
@AndroidEntryPoint
class NoticeDetailActivity : BaseActivity<ActivityNoticeDetailBinding,NoticeIntent,NoticeViewModel>() {

    @Autowired
    lateinit var nid:String

    override fun getVM(): NoticeViewModel {
        return viewModels<NoticeViewModel>().value
    }

    override fun getBind(): ActivityNoticeDetailBinding {
        return ActivityNoticeDetailBinding.inflate(layoutInflater)
    }

    override fun initData() {
        lifecycleScope.launch {
            vm.uiState.collect{
                when(it){
                    is UiState.onSuccess<*> ->{
                        val item = it.data as NoticeBeanItem
                        binding.bean=item
                    }

                    else -> {}
                }
            }
        }
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        vm.sendIntent(NoticeIntent.getNoticeById(nid.toInt()))
    }

}